package br.com.imob.modelo;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author Gilton Nascimento
 */
@Entity
@Table(name = "\"CONTA\"", catalog = "imob", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Conta.findAll", query = "SELECT c FROM Conta c"),
    @NamedQuery(name = "Conta.findByContaId", query = "SELECT c FROM Conta c WHERE c.contaId = :contaId"),
    
    @NamedQuery(name = "Conta.findByConta", query = "SELECT c FROM Conta c WHERE c.conta = :conta"),
    @NamedQuery(name = "Conta.findLikeByConta", query = "SELECT c FROM Conta c WHERE c.conta Like :conta"),
    
    @NamedQuery(name = "Conta.findByBanco", query = "SELECT c FROM Conta c WHERE c.banco = :banco"),
    @NamedQuery(name = "Conta.findLikeByBanco", query = "SELECT c FROM Conta c WHERE c.banco Like :banco"),
    
    @NamedQuery(name = "Conta.findByAgencia", query = "SELECT c FROM Conta c WHERE c.agencia = :agencia"),
    @NamedQuery(name = "Conta.findLikeByAgencia", query = "SELECT c FROM Conta c WHERE c.agencia Like :agencia"),
    
    @NamedQuery(name = "Conta.findByOperacao", query = "SELECT c FROM Conta c WHERE c.operacao = :operacao"),
    @NamedQuery(name = "Conta.findLikeByOperacao", query = "SELECT c FROM Conta c WHERE c.operacao Like :operacao")
    })
public class Conta implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
//  <editor-fold defaultstate="collapsed" desc="Geradores de Sequencias">
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
    @SequenceGenerator(name = "SEQ_STORE", sequenceName = "next_conta")// </editor-fold>
    @Basic(optional = false)
    @Column(name = "conta_id", nullable = false)
    private Integer contaId;
    @Basic(optional = false)
    @Column(name = "conta", nullable = false, length = 50)
    private String conta;
    @Column(name = "banco", length = 80)
    private String banco;
    @Column(name = "agencia", length = 20)
    private String agencia;
    @Column(name = "operacao", length = 20)
    private String operacao;
    @JoinColumn(name = "pessoa_id", referencedColumnName = "pessoa_id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Pessoa pessoa;
    @JoinColumn(name = "empresa_id", referencedColumnName = "empresa_id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Empresa empresa;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "conta", fetch = FetchType.LAZY)
    private List<Contrato> contratoList;

    public Conta() {
    }

    public Conta(Integer id) { this.contaId = id; }
    public Conta(String cont) { conta = cont; }

    public Conta(int id, String tipoStr, String arg) {
    	contaId = id;
    	if( "conta".equalsIgnoreCase(tipoStr) ) 	conta = arg;
    	if( "banco".equalsIgnoreCase(tipoStr) ) 	banco = arg;
    	if( "agencia".equalsIgnoreCase(tipoStr) ) 	agencia = arg;
    	if( "operacao".equalsIgnoreCase(tipoStr) )	operacao = arg;
    }
    
    public Conta(Integer id, String cont) {
        contaId = id;
        conta = cont;
    }
    
    
    public Conta(int id, String cont, String bank, String agency) {
    	this(id, cont);
    	banco = bank;
    	agencia = agency;
    }
    
    public Conta(int id, String cont, String bank, String agency, String operation) {
    	this(id, cont, bank, agency);
    	operacao = operation;
    }

	public Integer getContaId() {
        return contaId;
    }

    public void setContaId(Integer contaId) {
        this.contaId = contaId;
    }

    public String getConta() {
        return conta;
    }

    public void setConta(String conta) {
        this.conta = conta;
    }

    public String getBanco() {
        return banco;
    }

    public void setBanco(String banco) {
        this.banco = banco;
    }

    public String getAgencia() {
        return agencia;
    }

    public void setAgencia(String agencia) {
        this.agencia = agencia;
    }

    public String getOperacao() {
        return operacao;
    }

    public void setOperacao(String operacao) {
        this.operacao = operacao;
    }

    public Pessoa getPessoa() {
        return pessoa;
    }

    public void setPessoa(Pessoa pessoa) {
        this.pessoa = pessoa;
    }

    public Empresa getEmpresa() {
        return empresa;
    }

    public void setEmpresa(Empresa empresa) {
        this.empresa = empresa;
    }

    public List<Contrato> getContratoList() {
        return contratoList;
    }

    public void setContratoList(List<Contrato> contratoList) {
        this.contratoList = contratoList;
    }
    
    public Object[] getValues() {
    	Object[] values = {contaId, conta, banco, agencia, operacao};
    	return values;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (contaId != null ? contaId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Conta)) {
            return false;
        }
        Conta other = (Conta) object;
        if ((this.contaId == null && other.contaId != null) || (this.contaId != null && !this.contaId.equals(other.contaId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.imob.modelo.Conta[contaId=" + contaId + "]";
    }

}
